package cn.tedu.tourism.travelAgency.service.impl;

import cn.tedu.tourism.travelAgency.mapper.TravelAgencyMapper;
import cn.tedu.tourism.travelAgency.mapper.TravelDetailMapper;
import cn.tedu.tourism.travelAgency.pojo.dto.TravelAgencyQuery;
import cn.tedu.tourism.travelAgency.pojo.dto.TravelDetailQuery;
import cn.tedu.tourism.travelAgency.pojo.entity.TravelDetail;
import cn.tedu.tourism.travelAgency.pojo.vo.TravelDetailVO;
import cn.tedu.tourism.travelAgency.pojo.vo.TravelPackagesVO;
import cn.tedu.tourism.travelAgency.service.TravelAgencyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class TravelAgencyImpl implements TravelAgencyService {

    @Autowired
    private TravelAgencyMapper travelAgencyMapper;
    @Autowired
    private TravelDetailMapper travelDetailMapper;

    @Override
    public List<TravelPackagesVO> selectTravelAgent(TravelAgencyQuery travelAgencyQuery) {
        log.debug("旅行团套餐查询参数为:{}",travelAgencyQuery);
        Double price = travelAgencyQuery.getPrice();
        while(price!=null) {
            if (price < 1000) {
                travelAgencyQuery.setMinPrice(0.0);
                travelAgencyQuery.setMaxPrice(1000.0);
                List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
                log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
                return travelPackagesVOS;
            } else if (price > 1000 && price < 2000) {
                travelAgencyQuery.setMinPrice(1000.0);
                travelAgencyQuery.setMaxPrice(2000.0);
                List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
                log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
                return travelPackagesVOS;
            } else if (price > 2000 && price < 3000) {
                travelAgencyQuery.setMinPrice(2000.0);
                travelAgencyQuery.setMaxPrice(3000.0);
                List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
                log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
                return travelPackagesVOS;
            } else if (price > 3000 && price < 4000) {
                travelAgencyQuery.setMinPrice(3000.0);
                travelAgencyQuery.setMaxPrice(4000.0);
                List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
                log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
                return travelPackagesVOS;
            } else if (price > 4000 && price < 5000) {
                travelAgencyQuery.setMinPrice(4000.0);
                travelAgencyQuery.setMaxPrice(5000.0);
                List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
                log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
                return travelPackagesVOS;
            } else if (price < 5000) {
                travelAgencyQuery.setMinPrice(5000.0);
                travelAgencyQuery.setMaxPrice(null);
                List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
                log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
                return travelPackagesVOS;
            }
        }
        List<TravelPackagesVO> travelPackagesVOS = travelAgencyMapper.select(travelAgencyQuery);
        log.debug("旅行团套餐参数为:{}", travelPackagesVOS);
        return travelPackagesVOS;

    }

    @Override
    public List<String> selectCity() {
        List<String> cityArr = travelAgencyMapper.selectCity();
        return cityArr;
    }

    @Override
    public List<TravelDetailVO> searchTravelDetail(TravelDetailQuery travelDetailQuery) {
        List<TravelDetailVO> detail = travelDetailMapper.searchTravelDetail(travelDetailQuery);
        log.debug("旅行社详情为："+detail);
        return detail;
    }

    @Override
    public List<TravelDetailVO> searchTravelDetailCity(TravelDetailQuery travelDetailQuery) {
        List<TravelDetailVO> cities = travelDetailMapper.searchTravelDetailCity(travelDetailQuery);
        log.debug("城市的旅行社详情为："+cities);
        return cities;
    }
    @Override
    public List<TravelDetailVO> searchTravelDetailProvince(TravelDetailQuery travelDetailQuery) {
        List<TravelDetailVO> detail = travelDetailMapper.searchTravelDetailProvince(travelDetailQuery);
        log.debug("省份的旅行社详情为："+detail);
        return detail;
    }

    @Override
    public List<TravelDetailVO> selectProvince() {
        List<TravelDetailVO> provinces = travelDetailMapper.selectProvince();
        log.debug("省份为："+provinces);
        return provinces;
    }

    @Override
    public List<TravelDetailVO> selectMarket() {
        List<TravelDetailVO> markets = travelDetailMapper.selectMarket();
        log.debug("城市为："+markets);
        return markets;
    }
}
